package cn.gxa.j229.bug.finance.controller.borrowing;

import cn.gxa.j229.bug.finance.pojo.TbCheck;
import cn.gxa.j229.bug.finance.service.borrowing.LoanService;
import cn.gxa.j229.bug.finance.service.borrowing.TbCheckService;
import cn.gxa.j229.bug.finance.utils.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/tbCheck")
public class TbCheckController {
    @Resource
    TbCheckService tbCheckService = null;
    @Resource
    LoanService loanService =null;
    JsonResult jsonResult = new JsonResult();

    @PostMapping("/delete")
    @ResponseBody
    public Map deleteTbCheck(@RequestBody TbCheck tbCheck){
        int deleteById = tbCheckService.deleteById(tbCheck.getId());
        jsonResult.setCode("200");
        jsonResult.setMsg("删除审核信息成功");
        return jsonResult.getValues();
    }

    @PostMapping("/insert")
    @ResponseBody
    public Map insertSelectiveTbCheck(@RequestBody TbCheck tbCheck){
        int byNum = tbCheckService.findByNum(tbCheck.getNum());
        if(byNum!=0){
            tbCheckService.deleteByNum(tbCheck.getNum());
            tbCheckService.insertSelective(tbCheck);
        }else{
            tbCheckService.insertSelective(tbCheck);
        }
        jsonResult.setCode("200");
        jsonResult.setMsg("审核信息提交成功");
        return jsonResult.getValues();
    }

    @PostMapping("/find")
    @ResponseBody
    public Map findByIdTbCheck(@RequestBody TbCheck tbCheck){
        List<Map<String, Object>> findById = tbCheckService.findById(tbCheck.getId());
        jsonResult.setCode("200");
        jsonResult.setMsg("审核信息查询成功");
        return jsonResult.getValues();
    }

    @PostMapping("/update")
    @ResponseBody
    public Map updateByIdSelectiveTbCheck(@RequestBody TbCheck tbCheck){
        int updateByIdSelective = tbCheckService.updateByIdSelective(tbCheck);
        jsonResult.setCode("200");
        jsonResult.setMsg("更改的审核信息提交成功");
        return jsonResult.getValues();
    }
}
